package edu.sctu.nieyu.day20150616;


import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by user01 on 2015/6/16.
 */
public class UrlUtil {
    public String getHttpUrl(String path){
        int count = 0;
        try {
            URL url = new URL(path);
            byte[] bytes = new byte[1024];
            try {
                InputStream inputStream = url.openStream();

                while ((count = inputStream.read(bytes))!=-1){
                    System.out.println(new String(bytes,0,count,"utf-8"));
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return path;
    }
    public String getHttpUrls(String path){

        int count = 0;
       try {
         URL url = new URL(path);
           byte[] bytes = new byte[1024];
            try {
                URLConnection urlConnection = url.openConnection();
                urlConnection.connect();
                InputStream inputStream = urlConnection.getInputStream();

                while ((count = inputStream.read(bytes))!= -1){
                    System.out.println(new String(bytes,0,count,"gb2312"));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
      return path;
    }
}
